var createError = require('http-errors');
var express = require('express');
var cors = require('cors');
var swaggerInstall = require('./swagger/index.js');
var path = require('path');

var cookieParser = require('cookie-parser');
var logger = require('morgan');

var registerRoutes = require('./routes');
var {bodySession} = require('./config/userConfig');
var bodyParser = require('body-parser')
var app = express();
app.use(cors())

// app.use((req, res, next) => {
//   res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
//   res.setHeader('Pragma', 'no-cache');
//   res.setHeader('Expires', '0');
//   next();
// });
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'),{
  maxAge: '0s' // 禁用缓存
}));
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
bodySession(app)
// app.use('/', indexRouter);
swaggerInstall(app)
registerRoutes(app)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.json('error');
});

module.exports = app;
